/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MathLib.Geometry;

import java.io.BufferedOutputStream;
import java.io.PrintWriter;

/**
 *
 * @author marko
 */
public class Rectangle implements IFigure{
    public String Name="";
    protected Point2DDouble A;
    protected double a;
    protected double b;

    public Rectangle(){

    }

    public Rectangle(Point2DDouble A,double a, double b){
        this.A = A;
        this.a = a;
        this.b = b;
    }

    public double Ax(){return A.x;}
    public double Ay(){return A.y;}
    public Point2DDouble A(){
        return new Point2DDouble(A.x, A.y);
    }

    public double Bx(){return A.x+a;}
    public double By(){return A.y;}
    public Point2DDouble B(){
        return new Point2DDouble(A.x+a, A.y);
    }

    public double Cx(){return A.x+a;}
    public double Cy(){return A.y-b;}
    public Point2DDouble C(){
        return new Point2DDouble(A.x+a, A.y-b);
    }

    public double Dx(){return A.x;}
    public double Dy(){return A.y-b;}
    public Point2DDouble D(){
        return new Point2DDouble(A.x, A.y - b);
    }

    public double GetALength(){
        return a;
    }

    public double GetBLength(){
        return b;
    }

    public Point2DDouble GetA(){
        return new Point2DDouble(A);
    }

    public void SetALength(double a){
         this.a = a;
    }

    public void SetBLength(double b){
        this.b = b;
    }

    public void SetA(Point2DDouble A){
        this.A = A;
    }

    public boolean Include(Point2DDouble x){
        return ( (x.x>=A.x)&&(x.x<=A.x+a)&&(x.y<=A.y)&&(x.y>=A.y-b) );
    }

    public void printToFile(BufferedOutputStream out) {
        PrintWriter o = new PrintWriter(out);
        o.println("4 2 0 0");
        o.println(1+" "+this.A.x+" "+this.A.y);
        o.println(2+" "+this.Bx()+" "+this.By());
        o.println(3+" "+this.Cx()+" "+this.Cy());
        o.println(4+" "+this.Dx()+" "+this.Dy());
        o.println("4 0");
        o.println("1 1 2");
        o.println("2 2 3");
        o.println("3 3 4");
        o.println("4 4 1");
        o.println("0");
        o.close();
    }

    public void printToFileQuad(BufferedOutputStream out) {
        PrintWriter o = new PrintWriter(out);
        o.println("4");
        o.println(this.A.x+" "+this.A.y + " 2");
        o.println(this.Bx()+" "+this.By() + " 2");
        o.println(this.Cx()+" "+this.Cy() + " 2");
        o.println(this.Dx()+" "+this.Dy() + " 2");
        o.println("0\n 1");
        o.println("4 0 0");
        o.println("1 2 3 4");
        o.println("2 2 2 2");
        o.close();
    }

}
